
export function getTimeAgo(dateString) {
  const currentDate = new Date();
  const givenDate = new Date(dateString);
  const timeDiff = currentDate.getTime() - givenDate.getTime();

  // 计算天数
  const daysAgo = Math.floor(timeDiff / (1000 * 60 * 60 * 24));
  if (daysAgo < 1) {
    // 计算小时数
    const hoursAgo = Math.floor(timeDiff / (1000 * 60 * 60));
    if (hoursAgo < 1) {
      // 计算分钟数
      const minutesAgo = Math.floor(timeDiff / (1000 * 60));
      if (minutesAgo < 1) {
        return '刚刚';
      } else {
        return `${minutesAgo}分钟前`;
      }
    } else {
      return `${hoursAgo}小时前`;
    }
  } else if (daysAgo < 30) {
    return `${daysAgo}天前`;
  }

  // 计算月数
  const monthsAgo = Math.floor(daysAgo / 30);
  if (monthsAgo < 12) {
    return `${monthsAgo}个月前`;
  }

  // 计算年数
  const yearsAgo = Math.floor(monthsAgo / 12);
  return `${yearsAgo}年前`;
}





export function gotoHome(){
	uni.showModal({
		title:"提示",
		content:"页面有误将返回首页",
		showCancel:false,
		success: (res) => {
			if(res.confirm){
				uni.reLaunch({
					url:"/pages/Home/Home"
				})
			}
		}
	})
}
